package cn.tedu.csmall.passport.controller;

import cn.tedu.csmall.passport.service.IAdminService;
import cn.tedu.csmall.pojo.dto.AdminLoginDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.tedu.csmall.common.web.JsonResult;

/**
 * @author xiayiyou
 * @date 2022/6/16 17:15
 */

@RestController
@RequestMapping(value = "/admins",produces = "application/json;charset=utf-8")
public class AdminController {

    @Autowired
    private IAdminService adminService;

    @RequestMapping("/login")
    public JsonResult<String> login(AdminLoginDTO adminLoginDTO){
        String jwt = adminService.login(adminLoginDTO);
        return JsonResult.ok(jwt);

    }


    //以下是测试访问的请求
    @GetMapping("/hello")
    @PreAuthorize("hasAuthority('/ams/admin/read')") // 新增
    public String sayHello(){
        System.out.println("执行测试访问的/hello");
        return "hello~~~~";
    }
}
